import { IPSApplication } from '../ipsapplication';
import { IPSAppCounterRef } from '../control/ipsapp-counter-ref';
import { IPSAppDERS } from '../dataentity/ipsapp-ders';
import { IPSAppDataEntity } from '../dataentity/ipsapp-data-entity';
import { IPSAppDEView } from './ipsapp-deview';
import { IPSAppDEWFActionView } from './ipsapp-dewfaction-view';
import { IPSAppDEWFView } from './ipsapp-dewfview';
import { PSAppViewImpl } from './psapp-view-impl';
import { IPSAppWF } from '../wf/ipsapp-wf';
import { IPSAppWFVer } from '../wf/ipsapp-wfver';
import { IPSLanguageRes } from '../../res/ipslanguage-res';
import { IPSWFVersion } from '../../wf/ipswfversion';
import { IPSWorkflow } from '../../wf/ipsworkflow';

export class PSAppDEViewImpl extends PSAppViewImpl implements IPSAppDEView, IPSAppDEWFView, IPSAppDEWFActionView {
  /**
   * 获取应用实体视图的关系集合
   */
  protected psappderspaths: IPSAppDERS[][] | null = null;

  getPSAppDERSPaths(): IPSAppDERS[][] | null {
    if (this.psappderspaths != null) {
      return this.psappderspaths;
    }
    const value = this.M.getPSAppDERSPaths;
    if (value == null) {
      return null;
    }
    const arr: any[] = [];
    for (let i = 0; i < value.length; i++) {
      const psAppDERSs = value[i];
      if (psAppDERSs) {
        const subArr: any[] = [];
        for (let j = 0; j < psAppDERSs.length; j++) {
          subArr.push(this.getPSModel4('app.dataentity.IPSAppDERS', psAppDERSs[j], 'getPSAppDERSPaths') as IPSAppDERS);
        }
        arr.push(subArr);
      }
    }
    this.psappderspaths = arr;
    return this.psappderspaths;
  }

  /**
   * 获取应用实体视图的关系集合
   */

  get psAppDERSPaths(): IPSAppDERS[][] | null {
    return this.getPSAppDERSPaths();
  }

  get accUserMode(): 0 | 2 | 3 | 4 {
    return this.M.accUserMode;
  }

  protected cappslanguageres: IPSLanguageRes | null = null;

  getCapPSLanguageRes(): IPSLanguageRes | null {
    if (this.cappslanguageres != null) return this.cappslanguageres;
    const value = this.M.getCapPSLanguageRes;
    if (value == null) {
      return null;
    }
    this.cappslanguageres = this.getPSModel4('res.IPSLanguageRes', value, 'getCapPSLanguageRes') as IPSLanguageRes;
    return this.cappslanguageres;
  }

  get capPSLanguageRes(): IPSLanguageRes | null {
    return this.getCapPSLanguageRes();
  }

  getCapPSLanguageResMust(): IPSLanguageRes {
    const value = this.getCapPSLanguageRes();
    if (value == null) {
      throw new Error('未指定标题语言资源');
    }
    return value;
  }

  get caption(): string {
    return this.M.caption;
  }

  get extendMode(): 0 | 2 {
    return this.M.extendMode != null ? this.M.extendMode : 0;
  }

  get funcViewMode():
    | 'PICKUPVIEW'
    | 'EDITVIEW'
    | 'MAINVIEW'
    | 'INDEXDEPICKUPVIEW'
    | 'FORMPICKUPVIEW'
    | 'MPICKUPVIEW'
    | 'MDATAVIEW'
    | 'WFEDITVIEW'
    | 'WFMDATAVIEW'
    | 'WFSTARTVIEW'
    | 'WFACTIONVIEW'
    | 'WFUTILACTIONVIEW'
    | 'REDIRECTVIEW'
    | 'MOBPICKUPVIEW'
    | 'MOBEDITVIEW'
    | 'MOBMAINVIEW'
    | 'MOBINDEXDEPICKUPVIEW'
    | 'MOBFORMPICKUPVIEW'
    | 'MOBMPICKUPVIEW'
    | 'MOBMDATAVIEW'
    | 'MOBWFEDITVIEW'
    | 'MOBWFMDATAVIEW'
    | 'MOBWFSTARTVIEW'
    | 'MOBWFACTIONVIEW'
    | 'MOBWFUTILACTIONVIEW'
    | 'MOBREDIRECTVIEW' {
    return this.M.funcViewMode;
  }

  get funcViewParam(): string {
    return this.M.funcViewParam;
  }

  get height(): number {
    return this.M.height != null ? this.M.height : 0;
  }

  get openMode(): 'INDEXVIEWTAB' | 'POPUP' | 'POPUPMODAL' | 'POPUPAPP' | 'DRAWER_LEFT' | 'DRAWER_RIGHT' | 'DRAWER_TOP' | 'DRAWER_BOTTOM' | 'POPOVER' | 'USER' | 'USER2' | 'USER3' | 'USER4' {
    return this.M.openMode;
  }

  protected psappcounterref: IPSAppCounterRef | null = null;

  getPSAppCounterRef(): IPSAppCounterRef | null {
    if (this.psappcounterref != null) return this.psappcounterref;
    const value = this.M.getPSAppCounterRef;
    if (value == null) {
      return null;
    }
    this.psappcounterref = this.findPSAppCounterRef(value);
    return this.psappcounterref;
  }

  get psAppCounterRef(): IPSAppCounterRef | null {
    return this.getPSAppCounterRef();
  }

  getPSAppCounterRefMust(): IPSAppCounterRef {
    const value = this.getPSAppCounterRef();
    if (value == null) {
      throw new Error('未指定应用计数器引用');
    }
    return value;
  }

  protected psappwf: IPSAppWF | null = null;

  getPSAppWF(): IPSAppWF | null {
    if (this.psappwf != null) return this.psappwf;
    const value = this.M.getPSAppWF;
    if (value == null) {
      return null;
    }
    const ipsapplication = this.getParentPSModelObject('app.IPSApplication') as IPSApplication;
    if (ipsapplication != null) {
      this.psappwf = ipsapplication.findPSAppWF(value);
    }
    return this.psappwf;
  }

  get psAppWF(): IPSAppWF | null {
    return this.getPSAppWF();
  }

  getPSAppWFMust(): IPSAppWF {
    const value = this.getPSAppWF();
    if (value == null) {
      throw new Error('未指定应用工作流');
    }
    return value;
  }

  protected psappwfver: IPSAppWFVer | null = null;

  getPSAppWFVer(): IPSAppWFVer | null {
    if (this.psappwfver != null) return this.psappwfver;
    const value = this.M.getPSAppWFVer;
    if (value == null) {
      return null;
    }
    this.psappwfver = this.getPSAppWFMust().findPSAppWFVer(value);
    return this.psappwfver;
  }

  get psAppWFVer(): IPSAppWFVer | null {
    return this.getPSAppWFVer();
  }

  getPSAppWFVerMust(): IPSAppWFVer {
    const value = this.getPSAppWFVer();
    if (value == null) {
      throw new Error('未指定应用工作流版本');
    }
    return value;
  }

  get psDEViewCodeName(): string {
    return this.M.getPSDEViewCodeName;
  }

  getPSDEViewCodeName(): string {
    return this.M.getPSDEViewCodeName;
  }

  get psDEViewId(): string {
    return this.M.getPSDEViewId;
  }

  getPSDEViewId(): string {
    return this.M.getPSDEViewId;
  }

  protected pswfversion: IPSWFVersion | null = null;

  getPSWFVersion(): IPSWFVersion | null {
    if (this.pswfversion != null) return this.pswfversion;
    const value = this.M.getPSWFVersion;
    if (value == null) {
      return null;
    }
    this.pswfversion = this.getPSModel4('wf.IPSWFVersion', value, 'getPSWFVersion') as IPSWFVersion;
    return this.pswfversion;
  }

  get psWFVersion(): IPSWFVersion | null {
    return this.getPSWFVersion();
  }

  getPSWFVersionMust(): IPSWFVersion {
    const value = this.getPSWFVersion();
    if (value == null) {
      throw new Error('未指定工作流版本对象');
    }
    return value;
  }

  protected psworkflow: IPSWorkflow | null = null;

  getPSWorkflow(): IPSWorkflow | null {
    if (this.psworkflow != null) return this.psworkflow;
    const value = this.M.getPSWorkflow;
    if (value == null) {
      return null;
    }
    this.psworkflow = this.getPSModel4('wf.IPSWorkflow', value, 'getPSWorkflow') as IPSWorkflow;
    return this.psworkflow;
  }

  get psWorkflow(): IPSWorkflow | null {
    return this.getPSWorkflow();
  }

  getPSWorkflowMust(): IPSWorkflow {
    const value = this.getPSWorkflow();
    if (value == null) {
      throw new Error('未指定工作流对象');
    }
    return value;
  }

  protected parentpsappdataentity: IPSAppDataEntity | null = null;

  getParentPSAppDataEntity(): IPSAppDataEntity | null {
    if (this.parentpsappdataentity != null) return this.parentpsappdataentity;
    const value = this.M.getParentPSAppDataEntity;
    if (value == null) {
      return null;
    }
    this.parentpsappdataentity = this.getPSModel4('app.dataentity.IPSAppDataEntity', value, 'getParentPSAppDataEntity') as IPSAppDataEntity;
    return this.parentpsappdataentity;
  }

  get parentPSAppDataEntity(): IPSAppDataEntity | null {
    return this.getParentPSAppDataEntity();
  }

  getParentPSAppDataEntityMust(): IPSAppDataEntity {
    const value = this.getParentPSAppDataEntity();
    if (value == null) {
      throw new Error('未指定父应用实体');
    }
    return value;
  }

  protected subcappslanguageres: IPSLanguageRes | null = null;

  getSubCapPSLanguageRes(): IPSLanguageRes | null {
    if (this.subcappslanguageres != null) return this.subcappslanguageres;
    const value = this.M.getSubCapPSLanguageRes;
    if (value == null) {
      return null;
    }
    this.subcappslanguageres = this.getPSModel4('res.IPSLanguageRes', value, 'getSubCapPSLanguageRes') as IPSLanguageRes;
    return this.subcappslanguageres;
  }

  get subCapPSLanguageRes(): IPSLanguageRes | null {
    return this.getSubCapPSLanguageRes();
  }

  getSubCapPSLanguageResMust(): IPSLanguageRes {
    const value = this.getSubCapPSLanguageRes();
    if (value == null) {
      throw new Error('未指定子标题语言资源');
    }
    return value;
  }

  get subCaption(): string {
    return this.M.subCaption;
  }

  get tempMode(): 0 | 1 | 2 {
    return this.M.tempMode != null ? this.M.tempMode : 0;
  }

  get title(): string {
    return this.M.title;
  }

  protected titlepslanguageres: IPSLanguageRes | null = null;

  getTitlePSLanguageRes(): IPSLanguageRes | null {
    if (this.titlepslanguageres != null) return this.titlepslanguageres;
    const value = this.M.getTitlePSLanguageRes;
    if (value == null) {
      return null;
    }
    this.titlepslanguageres = this.getPSModel4('res.IPSLanguageRes', value, 'getTitlePSLanguageRes') as IPSLanguageRes;
    return this.titlepslanguageres;
  }

  get titlePSLanguageRes(): IPSLanguageRes | null {
    return this.getTitlePSLanguageRes();
  }

  getTitlePSLanguageResMust(): IPSLanguageRes {
    const value = this.getTitlePSLanguageRes();
    if (value == null) {
      throw new Error('未指定抬头语言资源');
    }
    return value;
  }

  get wFStepValue(): string {
    return this.M.wFStepValue;
  }

  get wFUtilType():
    | 'SENDBACK'
    | 'SUPPLYINFO'
    | 'ADDSTEPBEFORE'
    | 'ADDSTEPAFTER'
    | 'TAKEADVICE'
    | 'SENDCOPY'
    | 'REASSIGN'
    | 'USERACTION'
    | 'USERACTION2'
    | 'USERACTION3'
    | 'USERACTION4'
    | 'USERACTION5'
    | 'USERACTION6' {
    return this.M.wFUtilType;
  }

  get width(): number {
    return this.M.width != null ? this.M.width : 0;
  }

  get enableDP(): boolean {
    return this.M.enableDP;
  }

  get enableWF(): boolean {
    return this.M.enableWF != null ? this.M.enableWF : false;
  }

  get showCaptionBar(): boolean {
    return this.M.showCaptionBar != null ? this.M.showCaptionBar : true;
  }

  get wFIAMode(): boolean {
    return this.M.wFIAMode;
  }

  get cls(): string {
    return 'PSAppDEViewImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'app.view.IPSAppDEView' || cls == 'app.view.IPSAppDEWFActionView' || cls == 'app.view.IPSAppDEWFView' || cls == 'dataentity.IPSDataEntityObject') return true;
    return super.instanceof(cls);
  }
}
